package com.sanctuary.tests;

import java.io.PrintWriter;

import junit.framework.TestCase;

import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockJspWriter;

import com.sanctuary.interfaces.Product;
import com.sanctuary.interfaces.Service;
import com.sanctuary.tools.BaseTool;

public class PostItemTest extends TestCase {
	private static final String URL = "http://www.surveyusa.com/index.php/2008/03/06/electoral-math-as-of-030608-obama-280-mccain-258/";
	MockHttpServletRequest request = null;
	MockHttpServletResponse response = null;
	MockJspWriter writer = null;
	
	Service svc = null;
	
	public void testPost() {
		svc = (Service) BaseTool.IOC_ENGINE.getBean("postItem");
		assertNotNull("no service found",svc);
		
		request = new MockHttpServletRequest();
		response = new MockHttpServletResponse();
		writer = new MockJspWriter(new PrintWriter(System.out));
		
		request.addParameter("url",URL);
		request.addParameter("title","Test - " + System.currentTimeMillis());
		
		svc.setRequest(request);
		svc.setResponse(response);
		svc.setWriter(writer);
		
		try {
			Product p = svc.execute();
			p.print();
		} catch (Exception ex) {
			ex.printStackTrace(System.err);
			fail("boo!!");
		}
		
	}
	
	protected void setUp() throws Exception {
		super.setUp();
	}

}
